package org.kabeja.dxf.helpers;

/**
 * @author shutao
 * @since 2022/4/25 10:34
 */
public class HatchLineSegment {
    protected Point startPoint;
    protected Vector direction;
    protected double angle;
    protected double totalLength;
    protected double length;
    protected double currentLength;
    protected double[] pattern;
    protected double l;
    protected int index;
    protected ParametricLine line;

    public HatchLineSegment(Point var1, double var2, double var4) {
        this.startPoint = var1;
        this.angle = Math.toRadians(var2);
        this.totalLength = var4;
    }

    public HatchLineSegment(Point var1, Vector var2, double var3) {
        this.startPoint = var1;
        this.direction = var2;
        this.totalLength = var3;
    }

    public HatchLineSegment(ParametricLine var1, double var2, double var4, double[] var6) {
        this.startPoint = var1.getStartPoint();
        this.angle = Math.toRadians(this.angle);
        this.totalLength = var2;
        this.currentLength = var4;
        this.pattern = var6;
        this.line = var1;
        this.initialize(var4);
    }

    public Point getStartPoint() {
        return this.startPoint;
    }

    public double getLength() {
        return this.totalLength;
    }

    public Point getPoint(double var1) {
        Point var3 = new Point();
        var3.setX(this.startPoint.getX() + Math.cos(this.angle) * this.totalLength);
        var3.setY(this.startPoint.getY() + Math.sin(this.angle) * this.totalLength);
        return var3;
    }

    public Point getPointAt(double var1) {
        return this.line.getPointAt(var1);
    }

    public boolean hasNext() {
        return this.length <= this.totalLength;
    }

    public double next() {
        double var1 = this.currentLength;
        this.length += Math.abs(this.currentLength);
        if (this.index == this.pattern.length) {
            this.index = 0;
        }

        this.currentLength = this.pattern[this.index];
        ++this.index;
        return var1;
    }

    protected void initialize(double var1) {
        double var3 = 0.0D;

        for(int var5 = 0; var5 < this.pattern.length; ++var5) {
            var3 += Math.abs(this.pattern[var5]);
            if (var3 > var1) {
                this.currentLength = var3 - var1;
                if (this.pattern[var5] < 0.0D) {
                    this.currentLength *= -1.0D;
                }

                this.index = var5 + 1;
                return;
            }
        }

    }

    public boolean isSolid() {
        return this.pattern.length == 0;
    }
}
